package com.yiwei.zxp.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.support.v7.widget.RecyclerView;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yiwei.zxp.R;
import com.yiwei.zxp.activity.ShareDetailActivity;
import com.yiwei.zxp.api.model.ShareGoldListModel;
import com.yiwei.zxp.util.DateTime;
import com.yiwei.zxp.util.Spans;
import com.yiwei.zxp.util.Util;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class MyShareMoneyAdapter extends ItemAdapter<ShareGoldListModel.DatasBean, MyShareMoneyAdapter.DefaultHolder> {

    private final int textSize28;
    private final int textSize24;


    private Context context;

    public MyShareMoneyAdapter(Context context) {
        super(context);
        this.context = context;
        textSize28 = context.getResources().getDimensionPixelSize(R.dimen.x28);
        textSize24 = context.getResources().getDimensionPixelSize(R.dimen.x24);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_my_share_money, parent));
    }

    //    {
//        "order_id": 2,   //订单记录ID
//            "shared_gold": "5000.00",   //淘淘币
//            "status": 0,   //状态：状态：0-等待排位、1-已出彩、2-排位中
//            "buy_time": 1525766761,  //购买时间
//            "paiwei_date": null,  //排位日期
//            "last_back_time": 1538726761,  //最迟出彩时间
//            "true_back_time": 0,   //实际出彩时间
//    },
    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        ShareGoldListModel.DatasBean item = getItem(position);
        Spanned txtOne = Spans.with(context).font("目前排队位数：第" + item.id + "位", textSize28, 0xff000000).style(Typeface.BOLD).
//                font("（共享次数:" + item.paiwei_progress + "）", textSize24, 0xff999999).
                build();
        holder.txtTitle.setText(txtOne);
        Spanned txtTwo = Spans.with(context).font("最多可领淘淘币 ", textSize28, 0xff999999).
                font(item.shared_gold + "个", textSize24, 0xff333333).
                build();
        holder.txtContentLeft.setText(txtTwo);
        Spanned txtThree = Spans.with(context).font("预领取时间 ", textSize28, 0xff999999).
                font(DateTime.toDate(item.last_back_time * 1000), textSize24, 0xff333333).
                build();
        holder.txtContentRight.setText(txtThree);
        holder.layoutTotal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ShareDetailActivity.class);
                intent.putExtra("order_id", item.order_id);
                context.startActivity(intent);
                ((Activity) context).overridePendingTransition(R.anim.right_enter, R.anim.left_out);
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_title)
        TextView txtTitle;
        @BindView(R.id.txt_content_left)
        TextView txtContentLeft;
        @BindView(R.id.txt_content_right)
        TextView txtContentRight;
        @BindView(R.id.layout_total)
        LinearLayout layoutTotal;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
